package application.other;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableView;
import javafx.util.Callback;
import utils.EventUtils;

public class ShowEnergyConfigEvent implements Initializable {
	@FXML
	private TableView<String[]> tableView;

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		String[][] array = EventUtils.configArray;
		for (int i = 0; i < array[0].length; i++) {
			TableColumn<String[], String> column = new TableColumn<>(array[0][i]);
			column.setSortable(false);
			final int index = i;
			column.setCellValueFactory(
					new Callback<CellDataFeatures<String[], String>, ObservableValue<String>>() {

						@Override
						public ObservableValue<String> call(CellDataFeatures<String[], String> param) {
							// TODO Auto-generated method stub
							return new ReadOnlyStringWrapper(param.getValue()[index]);
						}
					});
			tableView.getColumns().add(column);
		}

		List<String[]> configList = new ArrayList<>();
		for (int i = 1; i < array.length; i++) {
			configList.add(array[i]);
		}
		ObservableList<String[]> configs = FXCollections.observableArrayList();
		configs.addAll(configList);
		tableView.setItems(configs);

		// TODO Auto-generated method stub

	}

}
